{include file="public/header"}
<title>订单录入</title>
</head>
<body>
<style>
    .col-sm-1 {
        width: 20% !important;
    }
</style>

<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <div class="ch-row ch-info-form">
            <p class="flex1">问题：</p>
            <div class="flex2 ch-pc-row ch-wrap">
                {volist name='go' id='v' key='i'}
                <div class="ch-row ch-align ch-checkbox">
                    <input id="ch-checkbox{$i}" type="checkbox" name="wen_a" class="wen_a" value="{$v.title}">
                    <label for="ch-checkbox{$i}">{$v.title}</label >
                </div>
                {/volist}
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">赠送项目：</p>
            <div class="flex2 ch-pc-row">
                <select class="give_a form-control ch-info-select" name="give_a">
                    <option selected="selected" value=" ">请选择</option>
                    {volist name='po' id='v'}
                    <option value="{$v.detailed_id}">{$v.detailed_title}</option>
                    {/volist}</select>
                <select class="give_b form-control" name="give_b">
                    <option selected="selected">请选择问题</option>
                </select>
            </div>
        </div>

        <div class="ch-row ch-info-form">
            <p class="flex1">施工天数：</p>
            <div class="flex2 ch-row ch-info-form-price">
                <input type="text" class="form-control gong" name="gong" >
            </div>
        </div>
        <div class="ch-row ch-info-form cdcd">
            <p class="flex1">优惠：</p>
            <div class="flex2 ch-row ch-info-form-price">
                <span>$</span>
                <input type="number" class="give_money" name="give_money" style="width: 100%" >
            </div>
        </div>


        <input class="order_id" type="hidden" name='order_id' value="{$data.order_id}">

        <div class="ch-row ch-info-form">
            <p class="flex1">备注：</p>
            <div class="flex2 ch-row ">
                <textarea name="give_remarks"
                          class="form-control " id="give_remarks"></textarea>
            </div>

        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">图片：</p>
            <div class="flex2 ch-row ">
                <div id="uploader-demo">
                    <!--用来存放item-->

                    <div id="fileList" class="uploader-list">

                    </div>
                    <div id="filePicker">选择图片</div>
                </div>
            </div>

        </div>
        <div class="ch-row ch-info-form" style="margin-top: 0 ">
            <div class="flex1">
                <button class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 提交
                </button>
            </div>
        </div>

    </form>
</article>
{include file="public/footer"}
<script>
    /***
     *
     *
     * 提交代码
     * */
    $('.radius').click(function () {
        var param = [];
        var wen_a='';
        var give_money=$('.give_money').val();
        var gong=$('.gong').val();
        var give_a=$('.give_a option:selected').text();
        var give_b=$('.give_b option:selected').text();
        var give_c=give_a+','+give_b;
        $("input[name='wen_a']:checkbox").each(function(index) {        if ($(this).prop("checked") === true) {

            wen_a+=$(this).val()+',';
        }
        });
        var order_id=$('.order_id').val();
        var give_remarks=$('#give_remarks').val();
        var result=[];

        $(".logo").each(function(){
            result.push($(this).val());
        });

        var pp={'give_money':give_money,'gong':gong,'give_remarks':give_remarks,'wen_a':wen_a,'order_id':order_id,'give_b':give_c,'capitalgo':result};

        if(localStorage.getItem(order_id+'z')){
            var op=JSON.parse(localStorage.getItem(order_id+'z'));
            op.push(pp);
            localStorage.setItem(order_id+'z',JSON.stringify(op))
        }else {
            param.push(pp);
            localStorage.setItem(order_id+'z',JSON.stringify(param))

        }
        window.parent.location.reload();
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);

    });

    /**
     * 赠送项目
     *
     **/
    $(".give_a").bind("change", function () {
        give_b();
    });

    function give_b() //市
    {
        var parent_ids = $(".give_a").find("option:selected").val(); //省id
        console.log(parent_ids);
        $.post("{:url('index/order/detailed')}", {detaileds_id: parent_ids}, function (data, textStatus, xhr) {
            var html;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['detailed_id'] + "'>" + data[i]['detailed_title'] + "</option>";
                }

            } else {
                html += "<option value=''>暂无数据</option>";
            }
            $('.give_b').html(html);
        });
    }





    /***
     * 图片上传
     */
    $("#img-change").click(function () {
        $("#file").click();
    });

    function delParent(object) {
        $(object).parent().remove();
        count -= 1;
    }

    var count = 1;
    $(function () {
        var $list = $("#fileList");
        var uploader = WebUploader.create({
            auto: true,
            // 文件接收服务端。
            server: "{:Url('index/upload/upload_file')}",

            // 选择文件的按钮。可选。
            pick: '#filePicker',

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            duplicate: true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            },
        });

        // 当有文件添加进来的时候
        uploader.on('fileQueued', function (file) {
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<div onclick="delParent(this)" style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>' +
                '<img style="width: 100px;height: 100px;">' +
                '<input name="logo" type="hidden" value="" class="logo">' +
                '<div class="info">' + file.name + '</div>' +
                '</div>'
                ),
                $img = $li.find('img');

            // $list为容器jQuery实例
            $list.append($li);


            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb(file, function (error, src) {
                if (error) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }

                $img.attr('src', src);
            }, 100, 100);
        });


        // 文件上传过程中创建进度条实时显示。
        uploader.on('uploadProgress', function (file, percentage) {
            var $li = $('#' + file.id),
                $percent = $li.find('.progress span');

            // 避免重复创建
            if (!$percent.length) {
                $percent = $('<p class="progress"><span></span></p>')
                    .appendTo($li)
                    .find('span');
            }


            $percent.css('width', percentage * 100 + '%');
        });
        var s = [];
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on('uploadSuccess', function (file, res) {
            var data = JSON.parse(res._raw);
            if (data.errcode == 300) {
                layer.alert(data.msg);
            }
            var url = data.data;
            count += 1;
            $('#' + file.id).find("logo").attr("src", url);
            $('#' + file.id).find("input").val(url);
            $('#' + file.id).addClass('upload-state-done');
        });

        // 文件上传失败，显示上传出错。
        uploader.on('uploadError', function (file) {
            var $li = $('#' + file.id),
                $error = $li.find('div.error');

            // 避免重复创建
            if (!$error.length) {
                $error = $('<div class="error"></div>').appendTo($li);
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on('uploadComplete', function (file) {
            $('#' + file.id).find('.progress').remove();
        });
    });

</script>
</body>
</html>